import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../config/api.dart';
class GoodsList extends StatefulWidget {
  Map arguments;
  GoodsList({Key key,this.arguments}) : super(key: key);

  @override
  _GoodsListState createState() => _GoodsListState(arguments:this.arguments);
}

class _GoodsListState extends State<GoodsList> {
   @override
   List goodsTwo=[];
  void initState(){
    super.initState();
 getHttp().then((res)=>{
  //  print('${res}我是')
  });
  getGoods();
  }
  void getGoods()async{
    getTwoGoods(arguments['id']['type']).then((value) => {
      print(value.data['message']),
      setState((){
        this.goodsTwo=value.data['message'];
      })
    });
  }
  List type=[
     {
            "id": 34,
            "goodsname": "桑蚕丝百搭白色吊带衫chic上衣内搭打底真丝吊带背心女夏外穿弹力",
            "price": 149,
            "maxpeople": 0,
            "url": "http://dbyxs.xyz:3005/uploads/da2f3af992ee1a796269e8ce91181032,http://dbyxs.xyz:3005/uploads/ba43fe5c7e4d865e3e02c8f07e7e017b,http://dbyxs.xyz:3005/uploads/8a6493807be953b65db916bcce89ceb7,http://dbyxs.xyz:3005/uploads/f811d22e61db0e6f6d508f3a7d0e4602,http://dbyxs.xyz:3005/uploads/f18913ccbed96d5a270d4b125acab3f3,",
            "status": "0",
            "banelurl": "http://dbyxs.xyz:3005/uploads/a26d7fc377a230a2116e25114e2d777d,http://dbyxs.xyz:3005/uploads/27de6876c83a42e0f31efebcedb3a85b,http://dbyxs.xyz:3005/uploads/d4911549da57ba716a5fdad3784ddfec,http://dbyxs.xyz:3005/uploads/3a371350e376e7a5bcd0f8cf77fd3e06,http://dbyxs.xyz:3005/uploads/88eda3cf7e43565ea763c0af38294513,",
            "type": 3,
            "gender": "1",
            "dates": "",
            "commod": 100,
            "time": "2020-06-28T03:48:08.000Z",
            "tit": "黑色,白色,红色",
            "titxx": "S,M,L"
        },
  ];
  //类型商品
  List <Widget> _gettyeps()=>List.generate(this.goodsTwo.length, (index)  {
      return Container(
        width: ScreenUtil().setWidth(700),
        height: ScreenUtil().setHeight(300),
        child: InkWell(
          onTap: (){
            // print(this.goodsTwo[index]);
           Navigator.pushNamed(context, '/goodscommodity',arguments: {"id":this.goodsTwo[index]});
          },
          child: Card(child: 
          Row(
            children: <Widget>[
              Container(
                width: ScreenUtil().setWidth(250),
                height: ScreenUtil().setHeight(300),
                child: Image.network('${this.goodsTwo[index]['url'].split(',')[0]}',fit: BoxFit.cover,)
              ),
              SizedBox(width: 6,),
              Expanded(
                flex: 1,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text('${this.goodsTwo[index]['goodsname']}',style: TextStyle(fontSize:14,fontWeight: FontWeight.w600),maxLines: 2,overflow: TextOverflow.ellipsis,),
               //   SizedBox(height: 5,),
                  Container(
                    height: ScreenUtil().setHeight(60),
                    child: Row(
                      children: <Widget>[
                      Container(
                        width: ScreenUtil().setWidth(130),
                        
                        child: ListTile(
                          title: Text('参数',style: TextStyle(color:Colors.black38,fontSize: 14),),
                          subtitle: Text('${this.goodsTwo[index]['tit'].split(',')[0]}',style: TextStyle(fontSize:14),),
                        ),
                      ),
                       Container(
                        width: ScreenUtil().setWidth(130),
                        child: ListTile(
                          title: Text('规格',style: TextStyle(color:Colors.black38,fontSize: 14),),
                          subtitle: Text('${this.goodsTwo[index]['titxx'].split(',')[0]}',style: TextStyle(color:Colors.black38,fontSize: 16),),
                        ),
                      ),
                       Container(
                        width: ScreenUtil().setWidth(130),
                        child: ListTile(
                          title: Text('属性',style: TextStyle(color:Colors.black38,fontSize: 14),),
                          subtitle: Text('s',style: TextStyle(color:Colors.black38,fontSize: 16),),
                        ),
                      ),
                      ],
                    ),
                  ),
                  SizedBox(height: 25,),
                  Container(
                    width: double.infinity,
                    height: ScreenUtil().setHeight(50),
                    child: Text('￥${this.goodsTwo[index]['price']}',style: TextStyle(color:Colors.redAccent,fontSize: 16,fontWeight: FontWeight.w700),),
                  ),
                  //SizedBox(height: ,),
                  Container(
                    width: ScreenUtil().setWidth(140),
                    decoration: BoxDecoration(
                      border: Border.all(width:1,color:Colors.redAccent),
                      borderRadius: BorderRadius.circular(2),
                    ),
                    child: Text('公益宝贝',style: TextStyle(color:Colors.redAccent),),
                  )
                ],
              ))
            ],
          )
          ,),
        ),
      );
  });
  Map arguments;
  _GoodsListState({this.arguments});
  @override
  Widget build(BuildContext context) {
    if(this.goodsTwo==null){
        return Scaffold(
          appBar: AppBar(title: Text('${arguments['id']['title']}',style:TextStyle(), textAlign:TextAlign.right),),
          body: Container(
            child: Center(child:Text('数据加载中')),
          ),
        );
    }else{
      return Scaffold(
      appBar: AppBar(title: Text('${arguments['id']['title']}',style:TextStyle(), textAlign:TextAlign.right),),
      body: Container(
        color: Colors.pink[300],
        width: double.infinity,
        //height: 400,
        child: ListView(
          children: <Widget>[
            Column(
              children: _gettyeps(),
            )
          ],
        )
      ),
    );
    }
  }
}